

#ifndef UD_DBMAIN_H
#define UD_DBMAIN_H

#include <stddef.h>
#include "zadesk.h"
#ifdef _ZSOFT_WINDOWS_
#include <share.h>
#endif
#include "zgepnt3d.h"
#include "zgevec3d.h"
#include "zgeline3d.h"
#include "zAcHeapOpers.h"
#include "zadesk.h"
#include "zrxobject.h"
#include "zrxdlinkr.h"
#include "zrxiter.h"
#include "zrxditer.h"
#include "zrxsrvice.h"
#include "zdbptrar.h"
#include "zdbcolor.h"
#include "zdbidar.h"
#include "zdrawable.h"
#include "zdbsecurity.h"

class UcCmEntityColor;
class UcCmColor;
class UcDbBlockBegin;
class UcDbBlockEnd;
class UcDbDatabase;
class UcDbDatabaseIterator;
class UcDbDatabaseReactor;
class UcDbEntity;
class UcDbEntityReactor;
class UcDbImpDatabase;
class UcDbImpObject;
class UcDbObject;
class UcDbObjectReactor;
class UcDbServices;
class UcDbSpaceIterator;
class UcDbSystemInternals;
class UcDbXObject;
class UcDbBlockReference;
class UcDbSymbolTable;
class UcDbBlockTable;
class UcDbBlockTableRecord;    
class UcDbLayerTable;
class UcDbTextStyleTable;
class UcDbLinetypeTable;
class UcDbAbstractViewTable;
class UcDbViewTable;
class UcDbUCSTable;
class UcDbViewportTable;
class UcDbRegAppTable;
class UcDbDimStyleTable;
class UcDbDimStyleTableRecord;
class UcDbIdMapping;
class UcDbDictionary;
class UcDbDictionaryWithDefault;
class UcDbMline;
class UcDbMlineStyle;
class UcDbCurve;
class UcDbEllipse;
class UcDbSpline;
class UcDbRegion;
class UcDb3dSolid;
class UcDbBody;
class UcDbDate;
class UcDbExtents;
class UcDbAuditInfo;
class UcDbUndoController;
class UcDbTransactionManager;
class UcDbSpatialFilter;
class UcDbLayerFilter;
class UcGeFastTransform;
class UcGsNode;
class UcGsModel;
class UcGiContext;
class UcDbObjectIdGraph;
class UcDbLayerStateManager;
class UcDwgFileHandle;
class UcFileDependencyManager;
class UcDbTableStyle;
class UcFdFieldValue;
class UcDbField;
class UcDbSectionManager;
class UcDbDataLinkManager;
class UcGiMapper;
class UcDbAnnotationScale;

#include "zacdb.h"
#include "zdbhandle.h"
#include "zdbfiler.h"
#include "zads.h"
#include "zgept3dar.h"
#include "zdbintar.h"
#include "zdbsubeid.h"
#include "zdbaudita.h"
#include "ZRXExports.h"

#pragma pack(push, 8)

#ifndef _ZSOFT_WINDOWS_
#define _SH_DENYRW      0x10    /* deny read/write mode */
#define _SH_DENYWR      0x20    /* deny write mode */
#define _SH_DENYRD      0x30    /* deny read mode */
#define _SH_DENYNO      0x40    /* deny none mode */
#define _SH_SECURE      0x80    /* secure mode */
#endif

struct _GUID;
typedef struct _GUID CLSID;

class UcDbGripData;
typedef UcArray<UcDbGripData*, UcArrayMemCopyReallocator<UcDbGripData*>> UcDbGripDataPtrArray;
typedef UcArray<UcDbFullSubentPath,
        UcArrayObjectCopyReallocator<UcDbFullSubentPath> > UcDbFullSubentPathArray;

ZRX_DB_EXPORT_GLOBAL extern const UcDbFullSubentPath kNullSubent;

UcDbServices* ucdbServices();

UcDb::DwgDataType ucdbGroupCodeToType(UcDb::DxfCode pCode);
void              ucdbFreeResBufContents(resbuf* pField);
bool              ucdbIsPersistentReactor(void *pSomething);
UcDbObjectId      ucdbPersistentReactorObjectId(void *pSomething);

bool   ucdbDisplayPreviewFromDwg(const ZTCHAR *pszDwgfilename,
                                 void* pPreviewWnd,
                                 const ZSoft::UInt32* pBgColor = nullptr);

bool ucdbIsCustomObject(const UcDbObjectId& id);

UCDB_PORT Ucad::ErrorStatus 
ucdbOpenObject(UcDbObject*& pObj, UcDbObjectId id, UcDb::OpenMode mode,
				bool openErased = false, const UcRxClass *pClass = nullptr);
Ucad::ErrorStatus
ucdbOpenUcDbObject(UcDbObject*& pObj, UcDbObjectId id, UcDb::OpenMode mode,
                   bool openErasedObject = false);
 
Ucad::ErrorStatus ZSOFT_STDCALL
ucdbOpenUcDbObject(UcDbObject*& pObj, UcDbObjectId id, UcDb::OpenMode mode,
                   const UcRxClass *pClass, bool openErasedObject = false);
 
Ucad::ErrorStatus
ucdbOpenUcDbEntity(UcDbEntity*& pEnt, UcDbObjectId id, UcDb::OpenMode mode,
                   bool openErasedEntity = false);

template<class T_OBJECT> inline Ucad::ErrorStatus
ucdbOpenObject(
    T_OBJECT *& pObj, UcDbObjectId id, UcDb::OpenMode mode,
    bool openErased = false)
{
    return ::ucdbOpenObject((UcDbObject * &)pObj, id, mode,
                                openErased, T_OBJECT::desc());
}
UCDB_PORT Ucad::ErrorStatus ucdbOpenObject(UcDbEntity *& pEnt, UcDbObjectId id, UcDb::OpenMode mode, bool openErased = false);

Ucad::ErrorStatus ucdbResurrectMeNow(const UcDbObjectId& id);

Ucad::ErrorStatus ucdbGetZdsName(zds_name&  objName, UcDbObjectId objId);
Ucad::ErrorStatus ucdbValKey(const zds_name name);
Ucad::ErrorStatus ucdbGetObjectId(UcDbObjectId& objId,
                                         const zds_name objName);

Ucad::ErrorStatus ucdbSetReferenced(UcDbObjectId objId);

UcDbVoidPtrArray* ucdbActiveDatabaseArray();

class UcDbViewTableRecord;
class UcDbViewport;
class UcDbObjectContextManager;

Ucad::ErrorStatus ucdbLoadMlineStyleFile(
                const ZTCHAR *sname, const ZTCHAR *fname);

Ucad::ErrorStatus ucdbLoadLineTypeFile(const ZTCHAR *ltname,
                                       const ZTCHAR *fname,
                                       UcDbDatabase *pDb);

void* ucdbAlloc(size_t);
void* ucdbRealloc(void *, size_t);
#ifdef MEM_DEBUG
void*             ucdbAlloc_dbg(size_t UCDBG_PARAM_DEC);
void*             ucdbRealloc_dbg(void *, size_t UCDBG_PARAM_DEC);
#define ucdbAlloc(a) ucdbAlloc_dbg(a, /*__FILE__*/"", /*__LINE__*/1)
#define ucdbRealloc(a, b) ucdbRealloc_dbg(a, b, /*__FILE__*/"", /*__LINE__*/1)
#endif
void  ucdbFree(void*);

Ucad::ErrorStatus ucdbValidateSetup(ZSoft::Int32 lcid);

Ucad::ErrorStatus ucdbCleanUp();

const ZTCHAR* ucdbOriginalXrefFullPathFor(const UcDbDatabase*);

UcGiContext * ucdbSetDefaultUcGiContext(UcGiContext *);

Ucad::ErrorStatus 
ucdbGetThumbnailBitmapFromDxfFile(const ZTCHAR* filename, void*& pBitmap);

Ucad::ErrorStatus ucdbSaveAs2004(UcDbDatabase* pDb, const ZTCHAR* fileName);

Ucad::ErrorStatus ucdbSaveAs2000(UcDbDatabase* pDb, const ZTCHAR* fileName);

Ucad::ErrorStatus ucdbDxfOutAs2004(UcDbDatabase* pDb, const ZTCHAR* fileName,
                                         const int precision = 16);
Ucad::ErrorStatus ucdbDxfOutAs2000(UcDbDatabase* pDb, const ZTCHAR* fileName,
                                         const int precision = 16);
Ucad::ErrorStatus ucdbDxfOutAsR12(UcDbDatabase* pDb, const ZTCHAR* fileName,
                                         const int precision = 16);
Ucad::ErrorStatus ucdbSaveAsR14(UcDbDatabase* pDb, const ZTCHAR* fileName);

long ucdbSetDbmod(UcDbDatabase* pDatabase, long lNewVal);

class ZSOFT_NO_VTABLE UcDbServices: public UcRxService
{
public:
    UCRX_DECLARE_MEMBERS(UcDbServices);
};

class UcDbDatabase: public UcRxObject, public UcHeapOperators
{
public:
    UCRX_DECLARE_MEMBERS(UcDbDatabase);

    UcDbDatabase(bool buildDefaultDrawing = true,
                 bool noDocument = false);
    virtual ~UcDbDatabase();
    Ucad::ErrorStatus addUcDbObject(UcDbObject*    pObj);
    Ucad::ErrorStatus addUcDbObject(UcDbObjectId&  objId,
                                    UcDbObject*    pObj);

    static Ucad::ErrorStatus markObjectNonPersistent(UcDbObjectId id, bool value);
    static bool isObjectNonPersistent(UcDbObjectId id);

    Ucad::ErrorStatus getBlockTable     (UcDbSymbolTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getLayerTable     (UcDbSymbolTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getTextStyleTable (UcDbSymbolTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getLinetypeTable  (UcDbSymbolTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getViewTable      (UcDbSymbolTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getUCSTable       (UcDbSymbolTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getViewportTable  (UcDbSymbolTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getRegAppTable    (UcDbSymbolTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getDimStyleTable  (UcDbSymbolTable*& pTable,
                                         UcDb::OpenMode    mode);

    Ucad::ErrorStatus getSymbolTable    (UcDbBlockTable*&     pTable,
                                         UcDb::OpenMode       mode);
    Ucad::ErrorStatus getSymbolTable    (UcDbLayerTable*&     pTable,
                                         UcDb::OpenMode       mode);
    Ucad::ErrorStatus getSymbolTable    (UcDbTextStyleTable*& pTable,
                                         UcDb::OpenMode       mode);
    Ucad::ErrorStatus getSymbolTable    (UcDbLinetypeTable*&  pTable,
                                         UcDb::OpenMode       mode);
    Ucad::ErrorStatus getSymbolTable    (UcDbViewTable*&      pTable,
                                         UcDb::OpenMode       mode);
    Ucad::ErrorStatus getSymbolTable    (UcDbUCSTable*&       pTable,
                                         UcDb::OpenMode       mode);
    Ucad::ErrorStatus getSymbolTable    (UcDbViewportTable*&  pTable,
                                         UcDb::OpenMode       mode);
    Ucad::ErrorStatus getSymbolTable    (UcDbRegAppTable*&    pTable,
                                         UcDb::OpenMode       mode);
    Ucad::ErrorStatus getSymbolTable    (UcDbDimStyleTable*&  pTable,
                                         UcDb::OpenMode       mode);

    Ucad::ErrorStatus getGroupDictionary   (UcDbDictionary*& pDict,
                                            UcDb::OpenMode mode);
    Ucad::ErrorStatus getMLStyleDictionary (UcDbDictionary*& pDict,
                                            UcDb::OpenMode mode);
    Ucad::ErrorStatus getLayoutDictionary  (UcDbDictionary*& pDict,
                                            UcDb::OpenMode mode);
    Ucad::ErrorStatus getPlotStyleNameDictionary(
                                            UcDbDictionaryWithDefault*& pDict,
                                            UcDb::OpenMode mode);
    Ucad::ErrorStatus getMaterialDictionary(UcDbDictionary*& pDict,
                                            UcDb::OpenMode mode);
    Ucad::ErrorStatus getVisualStyleDictionary(UcDbDictionary*& pDict,
                                            UcDb::OpenMode mode);
    Ucad::ErrorStatus getColorDictionary   (UcDbDictionary*& pDict,
                                            UcDb::OpenMode mode);
	
	Ucad::ErrorStatus getScaleListDictionary(UcDbDictionary*& pDict,
											UcDb::OpenMode mode);
	
    Ucad::ErrorStatus getNamedObjectsDictionary(
                                            UcDbDictionary*& pDict,
                                            UcDb::OpenMode mode);

    Ucad::ErrorStatus getBlockTable     (UcDbBlockTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getLayerTable     (UcDbLayerTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getTextStyleTable (UcDbTextStyleTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getLinetypeTable  (UcDbLinetypeTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getViewTable      (UcDbViewTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getUCSTable       (UcDbUCSTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getViewportTable  (UcDbViewportTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getRegAppTable    (UcDbRegAppTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getDimStyleTable  (UcDbDimStyleTable*& pTable,
                                         UcDb::OpenMode    mode);
    Ucad::ErrorStatus getPlotSettingsDictionary(UcDbDictionary*& pTable,
                                         UcDb::OpenMode    mode);
    UcDbObjectId      getSectionManager (void) const;
    Ucad::ErrorStatus getSectionManager (UcDbSectionManager*& pMgr,
                                         UcDb::OpenMode mode) const;
    UcDbObjectId    dataLinkDictionaryId(void) const;
    Ucad::ErrorStatus getDataLinkDictionary(UcDbDictionary*& pDict,
                                            UcDb::OpenMode mode);
    UcDbDataLinkManager*getDataLinkManager(void) const;
    Ucad::ErrorStatus updateDataLink    (UcDb::UpdateDirection nDir,
                                         UcDb::UpdateOption nOption);
    UCDB_PORT UcDbObjectId  blockTableId() const;
    UCDB_PORT UcDbObjectId  layerTableId() const;
    UCDB_PORT UcDbObjectId  textStyleTableId() const;
    UCDB_PORT UcDbObjectId  linetypeTableId() const;
    UCDB_PORT UcDbObjectId  viewTableId() const;
    UCDB_PORT UcDbObjectId  UCSTableId() const;
    UCDB_PORT UcDbObjectId  viewportTableId() const;
    UCDB_PORT UcDbObjectId  regAppTableId() const;
    UCDB_PORT UcDbObjectId  dimStyleTableId() const;
    UCDB_PORT UcDbObjectId  mLStyleDictionaryId() const;
    UCDB_PORT UcDbObjectId  groupDictionaryId() const;
    UCDB_PORT UcDbObjectId  layoutDictionaryId() const;
    UCDB_PORT UcDbObjectId  plotStyleNameDictionaryId() const;
    UCDB_PORT UcDbObjectId  materialDictionaryId() const;
    UCDB_PORT UcDbObjectId  visualStyleDictionaryId() const;
    UCDB_PORT UcDbObjectId  colorDictionaryId() const;
    UCDB_PORT UcDbObjectId  scaleListDictionaryId() const;
    UCDB_PORT UcDbObjectId  namedObjectsDictionaryId() const;
    UCDB_PORT UcDbObjectId  plotSettingsDictionaryId() const;

    UcDbObjectId layerZero() const;
    UcDbObjectId continuousLinetype() const;
    UcDbObjectId byLayerLinetype() const;
    UcDbObjectId byBlockLinetype() const;

    UcDbObjectId globalMaterial() const;
    UcDbObjectId byLayerMaterial() const;
    UcDbObjectId byBlockMaterial() const;

    UcDbObjectId paperSpaceVportId() const;
    UcDbObjectId currentSpaceId() const;

    Ucad::ErrorStatus purge(UcDbObjectIdArray& ids);
    Ucad::ErrorStatus purge(UcDbObjectIdGraph& idGraph);
    Ucad::ErrorStatus countHardReferences(const UcDbObjectIdArray& ids,
                                          ZSoft::UInt32* pCount);

    Ucad::ErrorStatus getUcDbObjectId(UcDbObjectId& retId,
                                      bool createIfNotFound,
                                      const UcDbHandle& objHandle,
                                      ZSoft::UInt32 xRefId = 0);

    const ZTCHAR* classDxfName(const UcRxClass* pClass);

	enum OpenMode {
		kForReadAndReadShare =    1, 
		kForReadAndWriteNoShare = 2, 
		kForReadAndAllShare =     3, 
		kTryForReadShare =        4 
	};
	Ucad::ErrorStatus readDwgFile(const ZTCHAR* fileName,
		OpenMode openmode,
		bool bAllowCPConversion = false,
		const wchar_t* wszPassword = nullptr);
    Ucad::ErrorStatus readDwgFile(const ZTCHAR* fileName,
                                  const int shmode = _SH_DENYWR,
                                  bool bAllowCPConversion = false,
                                  const wchar_t* wszPassword = nullptr);
    Ucad::ErrorStatus readDwgFile(UcDwgFileHandle *pDwgFile,
                                  bool bAllowCPConversion = false,
                                  const wchar_t* wszPassword = nullptr);

    UCDB_PORT void           setFullSaveRequired();
	inline Ucad::ErrorStatus saveAs(const ZTCHAR* fileName,
									const SecurityParams* pSecParams = 0)
	{
		return saveAs(fileName, true, UcDb::kDHL_CURRENT, pSecParams);
	}

	Ucad::ErrorStatus saveAs(const ZTCHAR* fileName,
							 const bool bBakAndRename,
							 const UcDb::UcDbDwgVersion dwgVer = UcDb::kDHL_CURRENT,
							 const SecurityParams* pSecParams = 0);

    Ucad::ErrorStatus save();
    Ucad::ErrorStatus dxfIn(const ZTCHAR* dxfFilename,
                            const ZTCHAR* logFilename=nullptr);
	Ucad::ErrorStatus dxfOut(const ZTCHAR* fileName,
							int precision = 16,
							UcDb::UcDbDwgVersion dwgVer = UcDb::kDHL_CURRENT,
							bool saveThumbnailImage = false);

    Ucad::ErrorStatus closeInput(bool bCloseFile = false);

    int approxNumObjects() const;
    ZSoft::Int32 numberOfSaves() const;
    const ZTCHAR * originalFileName() const;
    UcDb::UcDbDwgVersion lastSavedAsVersion() const;
    UcDb::UcDbDwgVersion originalFileVersion() const;
    UcDb::UcDbDwgVersion originalFileSavedByVersion() const;
    UcDb::MaintenanceReleaseVersion lastSavedAsMaintenanceVersion() const;
    UcDb::MaintenanceReleaseVersion originalFileMaintenanceVersion() const;
    UcDb::MaintenanceReleaseVersion originalFileSavedByMaintenanceVersion() const;

    UcDwgFileHandle * inputFiler() const;

    Ucad::ErrorStatus wblock(UcDbDatabase*& pOutputDb,
                             const UcDbObjectIdArray& outObjIds,
                             const UcGePoint3d& basePoint);

    Ucad::ErrorStatus wblock(UcDbDatabase* pOutputDb,  
                             const UcDbObjectIdArray& outObjIds,
                             const UcGePoint3d& basePoint,
                             UcDb::DuplicateRecordCloning drc);  

    Ucad::ErrorStatus wblock(UcDbDatabase*& pOutputDb, UcDbObjectId blockId);
    Ucad::ErrorStatus wblock(UcDbDatabase*& pOutputDb);

    void              forceWblockDatabaseCopy();

    Ucad::ErrorStatus insert(UcDbObjectId& blockId, const ZTCHAR* pBlockName,
        UcDbDatabase* pDb,
        bool preserveSourceDatabase = true);

    Ucad::ErrorStatus insert(const UcGeMatrix3d& xform, UcDbDatabase* pDb,
        bool preserveSourceDatabase = true);

    Ucad::ErrorStatus insert(UcDbObjectId& blockId, 
        const ZTCHAR* pSourceBlockName,
        const ZTCHAR* pDestinationBlockName,
        UcDbDatabase* pDb,
        bool preserveSourceDatabase = true);

    Ucad::ErrorStatus deepCloneObjects(UcDbObjectIdArray& objectIds,
        UcDbObjectId& owner, UcDbIdMapping& idMap,
        bool deferXlation = false);
       
    Ucad::ErrorStatus wblockCloneObjects(UcDbObjectIdArray& objectIds,
        UcDbObjectId& owner, UcDbIdMapping& idMap,
        UcDb::DuplicateRecordCloning drc,
        bool deferXlation = false);

    void              abortDeepClone(UcDbIdMapping& idMap);

    void              addReactor(UcDbDatabaseReactor* pReactor) const;
    void              removeReactor(UcDbDatabaseReactor* pReactor) const;

    Ucad::ErrorStatus audit(UcDbAuditInfo* pInfo);
    Ucad::ErrorStatus auditXData(UcDbAuditInfo* pInfo);

    UcDbUndoController* undoController() const;
    void              disableUndoRecording(bool disable);
    bool              undoRecording() const ;

    UcDbTransactionManager* transactionManager() const;

    UcFileDependencyManager* fileDependencyManager() const;

    ZSoft::UInt8      maintenanceReleaseVersion() const;

    Ucad::ErrorStatus restoreOriginalXrefSymbols();
    Ucad::ErrorStatus restoreForwardingXrefSymbols();

    UcDbObjectId      xrefBlockId() const;

    void*             thumbnailBitmap() const;
    Ucad::ErrorStatus setThumbnailBitmap(void* pBmp);
    bool              retainOriginalThumbnailBitmap() const;
    void              setRetainOriginalThumbnailBitmap(bool retain);
    bool              isEMR() const;

    bool                  setSecurityParams(const SecurityParams* pSecParams,
                                            bool bSetDbMod = true);
    const SecurityParams* cloneSecurityParams();
    static void           disposeSecurityParams(const SecurityParams* pSecParams);

    bool dimaso() const;
    Ucad::ErrorStatus setDimaso(bool aso);

    bool dimsho() const;
    Ucad::ErrorStatus setDimsho(bool sho);

    bool plinegen() const;
    Ucad::ErrorStatus setPlinegen(bool gen);

    bool orthomode() const;
    Ucad::ErrorStatus setOrthomode(bool mode);

    bool regenmode() const;
    Ucad::ErrorStatus setRegenmode(bool mode);

    bool fillmode() const;
    Ucad::ErrorStatus setFillmode(bool mode);

    bool qtextmode() const;
    Ucad::ErrorStatus setQtextmode(bool mode);

    bool psltscale() const;
    Ucad::ErrorStatus setPsltscale(bool scale);

    bool limcheck() const;
    Ucad::ErrorStatus setLimcheck(bool check);

    bool blipmode() const;
    Ucad::ErrorStatus setBlipmode(bool mode);

    ZSoft::Int16 saveproxygraphics() const;
    Ucad::ErrorStatus setSaveproxygraphics(ZSoft::Int16 saveimg);

    ZSoft::Int16 delUsedObj() const;
    Ucad::ErrorStatus setDelUsedObj(ZSoft::Int16 deleteObj);

    bool dispSilh() const;
    Ucad::ErrorStatus setDispSilh(bool silh);

    bool plineEllipse() const;
    Ucad::ErrorStatus setPlineEllipse(bool pline);

    bool usrtimer() const;
    Ucad::ErrorStatus setUsrtimer(bool timer);

    bool skpoly() const;
    Ucad::ErrorStatus setSkpoly(bool asPoly);

    bool angdir() const;
    Ucad::ErrorStatus setAngdir(bool dir);

    bool splframe() const;
    Ucad::ErrorStatus setSplframe(bool disp);

    ZSoft::UInt8 xclipFrame() const;
    Ucad::ErrorStatus setXclipFrame(ZSoft::UInt8 disp);

    bool attreq() const;
    Ucad::ErrorStatus setAttreq(bool req);

    bool attdia() const;
    Ucad::ErrorStatus setAttdia(bool dia);

    bool mirrtext() const;
    Ucad::ErrorStatus setMirrtext(bool mirror);

    bool worldview() const;
    Ucad::ErrorStatus setWorldview(bool view);

    bool tilemode() const;
    Ucad::ErrorStatus setTilemode(bool mode);

    bool plimcheck() const;
    Ucad::ErrorStatus setPlimcheck(bool check);

    bool visretain() const;
    Ucad::ErrorStatus setVisretain(bool retain);

    ZSoft::Int16 dragmode() const;
    Ucad::ErrorStatus setDragmode(ZSoft::Int16 mode);

    ZSoft::Int16 treedepth() const;
    Ucad::ErrorStatus setTreedepth(ZSoft::Int16 depth);

    ZSoft::Int16 lunits() const;
    Ucad::ErrorStatus setLunits(ZSoft::Int16 lunits);

    ZSoft::Int16 luprec() const;
    Ucad::ErrorStatus setLuprec(ZSoft::Int16 prec);

    ZSoft::Int16 aunits() const;
    Ucad::ErrorStatus setAunits(ZSoft::Int16 aunits);

    ZSoft::Int16 auprec() const;
    Ucad::ErrorStatus setAuprec(ZSoft::Int16 auprec);

    ZSoft::Int16 attmode() const;
    Ucad::ErrorStatus setAttmode(ZSoft::Int16 mode);

    ZSoft::Int16 coords() const;
    Ucad::ErrorStatus setCoords(ZSoft::Int16 coords);

    ZSoft::Int16 pdmode() const;
    Ucad::ErrorStatus setPdmode(ZSoft::Int16 mode);

    ZSoft::Int16 pickstyle() const;
    Ucad::ErrorStatus setPickstyle(ZSoft::Int16 style);

    ZSoft::Int16 useri1() const;
    Ucad::ErrorStatus setUseri1(ZSoft::Int16 val);

    ZSoft::Int16 useri2() const;
    Ucad::ErrorStatus setUseri2(ZSoft::Int16 val);

    ZSoft::Int16 useri3() const;
    Ucad::ErrorStatus setUseri3(ZSoft::Int16 val);

    ZSoft::Int16 useri4() const;
    Ucad::ErrorStatus setUseri4(ZSoft::Int16 val);

    ZSoft::Int16 useri5() const;
    Ucad::ErrorStatus setUseri5(ZSoft::Int16 val);

    ZSoft::Int16 splinesegs() const;
    Ucad::ErrorStatus setSplinesegs(ZSoft::Int16 segs);

    ZSoft::Int16 surfu() const;
    Ucad::ErrorStatus setSurfu(ZSoft::Int16 u);

    ZSoft::Int16 surfv() const;
    Ucad::ErrorStatus setSurfv(ZSoft::Int16 v);

    ZSoft::Int16 surftype() const;
    Ucad::ErrorStatus setSurftype(ZSoft::Int16 type);

    ZSoft::Int16 surftab1() const;
    Ucad::ErrorStatus setSurftab1(ZSoft::Int16 tab1);

    ZSoft::Int16 surftab2() const;
    Ucad::ErrorStatus setSurftab2(ZSoft::Int16 tab2);

    ZSoft::Int16 splinetype() const;
    Ucad::ErrorStatus setSplinetype(ZSoft::Int16 type);

    ZSoft::Int16 shadedge() const;
    Ucad::ErrorStatus setShadedge(ZSoft::Int16 mode);

    ZSoft::Int16 shadedif() const;
    Ucad::ErrorStatus setShadedif(ZSoft::Int16 dif);

    UcDb::MeasurementValue measurement() const;
    Ucad::ErrorStatus setMeasurement(UcDb::MeasurementValue type);

    ZSoft::Int16 unitmode() const;
    Ucad::ErrorStatus setUnitmode(ZSoft::Int16 mode);

    ZSoft::Int16 maxactvp() const;
    Ucad::ErrorStatus setMaxactvp(ZSoft::Int16 max);

    ZSoft::Int16 isolines() const;
    Ucad::ErrorStatus setIsolines(ZSoft::Int16 isolines);

    ZSoft::UInt8 dwfframe() const;
    Ucad::ErrorStatus setDwfframe(ZSoft::UInt8);

    ZSoft::UInt8 dgnframe() const;
    Ucad::ErrorStatus setDgnframe(ZSoft::UInt8);

	ZSoft::Int8 pdfframe() const;
	Ucad::ErrorStatus setPdfframe(ZSoft::Int8 val);

    double ltscale() const;
    Ucad::ErrorStatus setLtscale(double scale);

    double textsize() const;
    Ucad::ErrorStatus setTextsize(double size);

    double tracewid() const;
    Ucad::ErrorStatus setTracewid(double width);

    double sketchinc() const;
    Ucad::ErrorStatus setSketchinc(double inc);

    double filletrad() const;
    Ucad::ErrorStatus setFilletrad(double radius);

    double thickness() const;
    Ucad::ErrorStatus setThickness(double thickness);

    UcDb::LineWeight  celweight() const;
    Ucad::ErrorStatus setCelweight(UcDb::LineWeight weight);

    static bool       isValidLineWeight(int weight);
    static UcDb::LineWeight getNearestLineWeight(int weight);

    UcDb::EndCaps endCaps() const;
    Ucad::ErrorStatus setEndCaps(UcDb::EndCaps type);

    UcDb::JoinStyle joinStyle() const;
    Ucad::ErrorStatus setJoinStyle(UcDb::JoinStyle style);

    bool lineWeightDisplay() const;
    Ucad::ErrorStatus setLineWeightDisplay(bool display);

    bool xrefEditEnabled() const;
    Ucad::ErrorStatus setXrefEditEnabled(bool enable);

    bool oleStartUp() const;
    Ucad::ErrorStatus setOleStartUp(bool val);

    double angbase() const;
    Ucad::ErrorStatus setAngbase(double angle);

    double pdsize() const;
    Ucad::ErrorStatus setPdsize(double size);

    double plinewid() const;
    Ucad::ErrorStatus setPlinewid(double width);

    double userr1() const;
    Ucad::ErrorStatus setUserr1(double val);

    double userr2() const;
    Ucad::ErrorStatus setUserr2(double val);

    double userr3() const;
    Ucad::ErrorStatus setUserr3(double val);

    double userr4() const;
    Ucad::ErrorStatus setUserr4(double val);

    double userr5() const;
    Ucad::ErrorStatus setUserr5(double val);

    double chamfera() const;
    Ucad::ErrorStatus setChamfera(double val);

    double chamferb() const;
    Ucad::ErrorStatus setChamferb(double val);

    double chamferc() const;
    Ucad::ErrorStatus setChamferc(double val);

    double chamferd() const;
    Ucad::ErrorStatus setChamferd(double val);

    double facetres() const;
    Ucad::ErrorStatus setFacetres(double facetres);
    double get3dDwfPrec() const;
    Ucad::ErrorStatus set3dDwfPrec(double DwfPrec);

    Ucad::ErrorStatus getMenu(ZTCHAR*& pOutput) const;

    bool hpInherit() const;
    Ucad::ErrorStatus setHpInherit(const bool inherit);

    UcGePoint2d hpOrigin() const;
    Ucad::ErrorStatus setHpOrigin(const UcGePoint2d& origin);

    const UcDbDate tdcreate() const;     
    const UcDbDate tdupdate() const;

    const UcDbDate tducreate() const;    
    const UcDbDate tduupdate() const;

    const UcDbDate tdindwg() const;      
    const UcDbDate tdusrtimer() const;

    UcCmColor cecolor() const;
    Ucad::ErrorStatus setCecolor(const UcCmColor& color);

    UcDbHandle handseed() const;
    Ucad::ErrorStatus setHandseed(const UcDbHandle& handle);

    UcDbObjectId clayer() const;
    Ucad::ErrorStatus setClayer(UcDbObjectId objId);

    UcDb::PlotStyleNameType getCePlotStyleNameId(UcDbObjectId& id) const;
    Ucad::ErrorStatus       setCePlotStyleName(UcDb::PlotStyleNameType,
                            UcDbObjectId newId = UcDbObjectId::kNull);
    
    UcDbObjectId textstyle() const;
    Ucad::ErrorStatus setTextstyle(UcDbObjectId objId);

    UcDbObjectId celtype() const;
    Ucad::ErrorStatus setCeltype(UcDbObjectId objId);

    UcDbObjectId cmaterial() const;
    Ucad::ErrorStatus setCmaterial(UcDbObjectId objId);

    UcDbObjectId dimstyle() const;
    Ucad::ErrorStatus setDimstyle(UcDbObjectId styleId);

    Ucad::ErrorStatus getDimstyleData(UcDbDimStyleTableRecord*& pRec) const;
    Ucad::ErrorStatus getDimstyleChildData(const UcRxClass *pDimClass,
                                           UcDbDimStyleTableRecord*& pRec,
                                           UcDbObjectId &style) const;
    UcDbObjectId getDimstyleChildId(const UcRxClass *pDimClass,
                                    UcDbObjectId &parentStyle) const;

    UcDbObjectId getDimstyleParentId(UcDbObjectId &childStyle) const;
                                           
    Ucad::ErrorStatus setDimstyleData(UcDbDimStyleTableRecord* pRec);
    Ucad::ErrorStatus setDimstyleData(UcDbObjectId id);

    UcDbObjectId cmlstyleID() const;
    Ucad::ErrorStatus setCmlstyleID(UcDbObjectId objId);

    ZSoft::Int16 cmljust() const;
    Ucad::ErrorStatus setCmljust(ZSoft::Int16 just);

    double cmlscale() const;
    Ucad::ErrorStatus setCmlscale(double scale);

    double celtscale() const;
    Ucad::ErrorStatus setCeltscale(double scale);

    UcGePoint3d pinsbase() const;
    Ucad::ErrorStatus setPinsbase(const UcGePoint3d& base);

    UcGePoint3d pextmin() const;

    UcGePoint3d pextmax() const;

    Ucad::ErrorStatus setPextmin(const UcGePoint3d& min);
    Ucad::ErrorStatus setPextmax(const UcGePoint3d& max);

    UcGePoint2d plimmin() const;
    Ucad::ErrorStatus setPlimmin(const UcGePoint2d& min);

    UcGePoint2d plimmax() const;
    Ucad::ErrorStatus setPlimmax(const UcGePoint2d& max);

    double pelevation() const;
    Ucad::ErrorStatus setPelevation(double elev);

    UcGePoint3d pucsorg() const;

    UcGeVector3d pucsxdir() const;

    UcGeVector3d pucsydir() const;

    UcDbObjectId pucsname() const;

    UcDbObjectId pucsBase() const;
    Ucad::ErrorStatus setPucsBase(const UcDbObjectId &ucsid);

    UcGePoint3d worldPucsBaseOrigin(UcDb::OrthographicView orthoView) const;
    Ucad::ErrorStatus setWorldPucsBaseOrigin(const UcGePoint3d& origin,
                                             UcDb::OrthographicView orthoView);

    bool isPucsOrthographic(UcDb::OrthographicView& orthoView) const;

    double cameraHeight() const;
    Ucad::ErrorStatus setCameraHeight(const double cameraHeight);

    double lensLength() const;
    Ucad::ErrorStatus setLensLength(const double lensLength);

    bool cameraDisplay() const;
    Ucad::ErrorStatus setCameraDisplay(const bool cameraDisplay);

    double stepsPerSec() const;
    Ucad::ErrorStatus setStepsPerSec(double stepsPerSec);

    double stepSize() const;
    Ucad::ErrorStatus setStepSize(double stepSize);

    bool realWorldScale() const;
    Ucad::ErrorStatus setRealWorldScale(const bool realWorldScale);
    UcGePoint3d insbase() const;
    Ucad::ErrorStatus setInsbase(const UcGePoint3d& base);

    UcGePoint3d extmin() const;

    UcGePoint3d extmax() const;

    Ucad::ErrorStatus updateExt(bool doBestFit = FALSE);

    Ucad::ErrorStatus setExtmin(const UcGePoint3d& min);
    Ucad::ErrorStatus setExtmax(const UcGePoint3d& max);

    UcGePoint2d limmin() const;
    Ucad::ErrorStatus setLimmin(const UcGePoint2d& min);

    UcGePoint2d limmax() const;
    Ucad::ErrorStatus setLimmax(const UcGePoint2d& max);

    double elevation() const;
    Ucad::ErrorStatus setElevation(double elev);

    UcGePoint3d ucsorg() const;

    UcGeVector3d ucsxdir() const;

    UcGeVector3d ucsydir() const;

    UcDbObjectId ucsname() const;

    UcDbObjectId ucsBase() const;
    Ucad::ErrorStatus setUcsBase(UcDbObjectId ucsid);

    UcGePoint3d worldUcsBaseOrigin(UcDb::OrthographicView orthoView) const;
    Ucad::ErrorStatus setWorldUcsBaseOrigin(const UcGePoint3d& origin,
                                            UcDb::OrthographicView orthoView);

    bool isUcsOrthographic(UcDb::OrthographicView& orthoView) const;

    #undef UDBDIMVAR_H                   
    #include "zdbdimvar.h"

    Ucad::ErrorStatus getDimpost(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus getDimapost(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus getDimblk(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus getDimblk1(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus getDimblk2(ZTCHAR*& pOutput) const;

    int dimfit() const;
    int dimunit() const;

    Ucad::ErrorStatus setDimfit(int fit);
    Ucad::ErrorStatus setDimunit(int unit);

    Ucad::ErrorStatus getDimRecentStyleList(UcDbObjectIdArray& objIds) const;

    Ucad::ErrorStatus loadLineTypeFile(const ZTCHAR *ltn, const ZTCHAR *filename);

    Ucad::ErrorStatus getProjectName(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus setProjectName(const ZTCHAR*);
    Ucad::ErrorStatus getHyperlinkBase(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus setHyperlinkBase(const ZTCHAR*);
    Ucad::ErrorStatus getStyleSheet(ZTCHAR*& pOutput) const;
    Ucad::ErrorStatus setStyleSheet(const ZTCHAR*);
    Ucad::ErrorStatus getFilename(const ZTCHAR* & pOutput) const;

    bool              isPartiallyOpened() const;
    Ucad::ErrorStatus applyPartialOpenFilters(
        const UcDbSpatialFilter* pSpatialFilter,
        const UcDbLayerFilter* pLayerFilter);

    void              disablePartialOpen();

    Ucad::ErrorStatus getFingerprintGuid(ZTCHAR*& guidString) const;
    Ucad::ErrorStatus setFingerprintGuid(const ZTCHAR *pNewGuid);

    Ucad::ErrorStatus getVersionGuid(ZTCHAR*& guidString) const;
    Ucad::ErrorStatus setVersionGuid(const ZTCHAR *pNewGuid);

    int tstackalign() const;
    Ucad::ErrorStatus setTStackAlign(int val);

    int tstacksize() const;
    Ucad::ErrorStatus setTStackSize(int val);

    UcDb::UnitsValue insunits() const;
    Ucad::ErrorStatus setInsunits(const UcDb::UnitsValue units);

    void                setGsModel(UcGsModel*);
    UcGsModel*          gsModel() const;

    void                setGsHighlightModel(UcGsModel*);
    UcGsModel*          gsHighlightModel() const;
    bool           plotStyleMode() const;

    double viewportScaleDefault() const;
    Ucad::ErrorStatus setViewportScaleDefault(double newDefaultVPScale);

    bool           dwgFileWasSavedByUeSoftSoftware() const;

    UcDbLayerStateManager *getLayerStateManager() const;
    UcDbObjectContextManager* objectContextManager() const;
    ZSoft::UInt8        sortEnts() const;
    Ucad::ErrorStatus   setSortEnts(ZSoft::UInt8 sortEnts);

    ZSoft::UInt8        drawOrderCtl() const;
    Ucad::ErrorStatus   setDrawOrderCtl(ZSoft::UInt8 val);
    
    ZSoft::UInt8        dimAssoc() const;
    Ucad::ErrorStatus setDimAssoc(ZSoft::UInt8 val);

    ZSoft::UInt8 hideText() const;
    Ucad::ErrorStatus setHideText(ZSoft::UInt8 val);

    ZSoft::UInt8  haloGap() const;
    Ucad::ErrorStatus setHaloGap(ZSoft::UInt8 val);

    ZSoft::UInt16 obscuredColor() const;
    Ucad::ErrorStatus setObscuredColor(ZSoft::UInt16 val);

    ZSoft::UInt8 obscuredLineType() const;
    Ucad::ErrorStatus setObscuredLineType(ZSoft::UInt8 val);

    ZSoft::UInt8  intersectDisplay() const;
    Ucad::ErrorStatus setIntersectDisplay(ZSoft::UInt8 val);

    ZSoft::UInt16 intersectColor() const;
    Ucad::ErrorStatus setIntersectColor(ZSoft::UInt16 val);

    Ucad::ErrorStatus getTableStyleDictionary(UcDbDictionary*& pDict,
                                              UcDb::OpenMode mode);
    UcDbObjectId  tableStyleDictionaryId() const;

    UcDbObjectId tablestyle() const;
    Ucad::ErrorStatus setTablestyle(UcDbObjectId objId);
    Ucad::ErrorStatus getMLeaderStyleDictionary(UcDbDictionary*& pDict,
                                              UcDb::OpenMode mode);
    UcDbObjectId  mleaderStyleDictionaryId() const;
    UcDbObjectId mleaderstyle() const;
    Ucad::ErrorStatus setMLeaderstyle(UcDbObjectId objId);

    Ucad::ErrorStatus evaluateFields(int nContext,
                                     const ZTCHAR* pszPropName= nullptr,
                                     UcDbDatabase* pDb      = nullptr,
                                     int* pNumFound         = nullptr,
                                     int* pNumEvaluated     = nullptr);
    Ucad::ErrorStatus getViewportArray(UcDbObjectIdArray& vportIds,
                                       bool bGetPaperspaceVports = true) const;
    Ucad::ErrorStatus getVisualStyleList(UcArray<const ZTCHAR*> & vstyleList);

    ZSoft::UInt8  solidHist() const;
    Ucad::ErrorStatus setSolidHist(ZSoft::UInt8 val);

    ZSoft::UInt8  showHist() const;
    Ucad::ErrorStatus setShowHist(ZSoft::UInt8 val);

    double psolWidth() const;
    Ucad::ErrorStatus setPsolWidth(double width);
    double psolHeight() const;
    Ucad::ErrorStatus setPsolHeight(double height);

    ZSoft::UInt16 loftParam() const;
    Ucad::ErrorStatus setLoftParam(ZSoft::UInt16 flags);
    ZSoft::UInt8 loftNormals() const;
    Ucad::ErrorStatus setLoftNormals(ZSoft::UInt8 value);
    double loftAng1() const;
    Ucad::ErrorStatus setLoftAng1(double ang1);
    double loftAng2() const;
    Ucad::ErrorStatus setLoftAng2(double ang2);
    double loftMag1() const;
    Ucad::ErrorStatus setLoftMag1(double mag1);
    double loftMag2() const;
    Ucad::ErrorStatus setLoftMag2(double mag2);
    double latitude() const;
    Ucad::ErrorStatus setLatitude(double lat);
    double longitude() const;
    Ucad::ErrorStatus setLongitude(double lng);
    double northDirection() const;
    Ucad::ErrorStatus setNorthDirection(double northdir);
    UcDb::TimeZone timeZone() const;
    Ucad::ErrorStatus setTimeZone(UcDb::TimeZone tz);

    Ucad::ErrorStatus getTimeZoneInfo(UcDb::TimeZone tz, double& offset, UcString& desc) const;
    Ucad::ErrorStatus setTimeZoneAsUtcOffset(double offset);

    ZSoft::UInt8 lightGlyphDisplay() const;
    Ucad::ErrorStatus setLightGlyphDisplay(ZSoft::UInt8 val);
    ZSoft::UInt8 tileModeLightSynch() const;
    Ucad::ErrorStatus setTileModeLightSynch(ZSoft::UInt8 val);

    UcCmColor interfereColor() const;
    Ucad::ErrorStatus setInterfereColor(const UcCmColor& color);

    UcDbObjectId interfereObjVisStyle() const;
    Ucad::ErrorStatus setInterfereObjVisStyle(UcDbObjectId id);

    UcDbObjectId interfereVpVisStyle() const;
    Ucad::ErrorStatus setInterfereVpVisStyle(UcDbObjectId id);

    UcDbObjectId dragVisStyle() const;
    Ucad::ErrorStatus setDragVisStyle(UcDbObjectId id);

    ZSoft::UInt8 cshadow() const;
    Ucad::ErrorStatus setCshadow(ZSoft::UInt8 val);

    double shadowPlaneLocation() const;
    Ucad::ErrorStatus setShadowPlaneLocation(double val);

    UcDbAnnotationScale* cannoscale() const;
    Ucad::ErrorStatus setCannoscale(UcDbAnnotationScale*);

    bool annoAllVisible() const;
    Ucad::ErrorStatus setAnnoAllVisible(bool allvis);

    bool annotativeDwg() const;
    Ucad::ErrorStatus setAnnotativeDwg(bool ao);

    bool msltscale() const;
    Ucad::ErrorStatus setMsltscale(bool val);

    ZSoft::UInt8 lightingUnits() const;
    Ucad::ErrorStatus setLightingUnits(ZSoft::UInt8 val);

    bool lightsInBlocks() const;
    Ucad::ErrorStatus setLightsInBlocks(bool val);

    ZSoft::Int16 dxeVal() const;
    Ucad::ErrorStatus setDxeVal(ZSoft::Int16 val);

private:
    friend class UcDbSystemInternals;
    UcDbImpDatabase* mpImpDb;
};

class UcDbObjectIterator: public UcRxObject, public UcHeapOperators
{
public:
    UCRX_DECLARE_MEMBERS(UcDbObjectIterator);
    virtual ~UcDbObjectIterator();

    bool           done() const;
    void           step(bool backwards = false, bool skipDeleted = true);
    void           setPosition(UcDbEntity*  pEnt);
    void           setPosition(UcDbObjectId  pObj);
    void           start(bool atEnd = false);
    UcDbEntity*    entity();
    UcDbObjectId   objectId();

private:
    friend class UcDbSystemInternals;
    UcDbObjectIterator();
    UcDbSpaceIterator* mpImpIterator;
};

class ZSOFT_NO_VTABLE UcDbObject: public UcGiDrawable, public UcHeapOperators
{
public:
    UCDB_DECLARE_MEMBERS(UcDbObject);

    virtual ~UcDbObject();

    UcDbObjectId      objectId() const;
    UcDbObjectId      ownerId() const;
    virtual Ucad::ErrorStatus setOwnerId(UcDbObjectId objId);
    void              getUcDbHandle(UcDbHandle& handle) const;
    UcDbDatabase*     database() const;
    Ucad::ErrorStatus createExtensionDictionary();
    UcDbObjectId      extensionDictionary() const;
    Ucad::ErrorStatus releaseExtensionDictionary();

    Ucad::ErrorStatus upgradeOpen();
    Ucad::ErrorStatus upgradeFromNotify(ZSoft::Boolean& wasWritable);
    Ucad::ErrorStatus downgradeOpen();
    Ucad::ErrorStatus downgradeToNotify(ZSoft::Boolean wasWritable);
    virtual Ucad::ErrorStatus subOpen(UcDb::OpenMode mode);

    Ucad::ErrorStatus cancel();
    virtual Ucad::ErrorStatus subCancel();

    Ucad::ErrorStatus close();
    Ucad::ErrorStatus closeAndPage(ZSoft::Boolean onlyWhenClean = true);
    virtual Ucad::ErrorStatus subClose();

    Ucad::ErrorStatus erase(ZSoft::Boolean erasing = true);
    virtual Ucad::ErrorStatus subErase(ZSoft::Boolean erasing);

    Ucad::ErrorStatus handOverTo(UcDbObject* newObject,
                                 ZSoft::Boolean keepXData = true,
                                 ZSoft::Boolean keepExtDict = true);
    virtual Ucad::ErrorStatus subHandOverTo(UcDbObject* newObject);

    Ucad::ErrorStatus swapIdWith(UcDbObjectId otherId, 
                                 ZSoft::Boolean swapXdata = false,
                                 ZSoft::Boolean swapExtDict = false);
    virtual Ucad::ErrorStatus subSwapIdWith(UcDbObjectId otherId,
                                 ZSoft::Boolean swapXdata = false,
                                 ZSoft::Boolean swapExtDict = false);

    virtual Ucad::ErrorStatus swapReferences (const UcDbIdMapping& idMap);

    virtual Ucad::ErrorStatus audit(UcDbAuditInfo* pAuditInfo);

    Ucad::ErrorStatus         dwgIn       (UcDbDwgFiler* pFiler);
    virtual Ucad::ErrorStatus dwgInFields (UcDbDwgFiler* pFiler);
    Ucad::ErrorStatus         dwgOut      (UcDbDwgFiler* pFiler) const;
    virtual Ucad::ErrorStatus dwgOutFields(UcDbDwgFiler* pFiler) const;

    Ucad::ErrorStatus         dxfIn       (UcDbDxfFiler* pFiler);
    virtual Ucad::ErrorStatus dxfInFields (UcDbDxfFiler* pFiler);
    Ucad::ErrorStatus         dxfOut      (UcDbDxfFiler* pFiler,
                                           ZSoft::Boolean allXdFlag,
                                           ZSoft::uchar* regAppTable) const;
    virtual Ucad::ErrorStatus dxfOutFields(UcDbDxfFiler* pFiler) const;

    virtual UcDb::DuplicateRecordCloning mergeStyle () const;

    virtual resbuf*           xData   (const ZTCHAR* regappName = nullptr) const;
    virtual Ucad::ErrorStatus setXData(const resbuf* xdata);
            Ucad::ErrorStatus xDataTransformBy(const UcGeMatrix3d& xform);

    Ucad::ErrorStatus         setBinaryData(const ZTCHAR * key,
                                            ZSoft::Int32         size,
                                            const char * data);
    Ucad::ErrorStatus         getBinaryData(const ZTCHAR * key,
                                            ZSoft::Int32 &       size,
                                            char *&      data) const;

    ZSoft::Boolean isEraseStatusToggled() const;
    ZSoft::Boolean isErased() const;
    ZSoft::Boolean isReadEnabled() const;
    ZSoft::Boolean isWriteEnabled() const;
    ZSoft::Boolean isNotifyEnabled() const;
    ZSoft::Boolean isModified() const;
    ZSoft::Boolean isModifiedXData() const;
    ZSoft::Boolean isModifiedGraphics() const;
    ZSoft::Boolean isNewObject() const;
    ZSoft::Boolean isNotifying() const;
    ZSoft::Boolean isUndoing() const;
    ZSoft::Boolean isCancelling() const;
    ZSoft::Boolean isReallyClosing() const;
    ZSoft::Boolean isTransactionResident() const;

    ZSoft::Boolean isAProxy() const;

    void assertReadEnabled() const;
    void assertWriteEnabled(ZSoft::Boolean autoUndo = true,
                            ZSoft::Boolean recordModified = true);
    void assertNotifyEnabled() const;

    void                      disableUndoRecording(ZSoft::Boolean disable);
    UcDbDwgFiler*             undoFiler();
    virtual Ucad::ErrorStatus applyPartialUndo(UcDbDwgFiler* undoFiler,
                                               UcRxClass*    classObj);

    void                      addReactor(UcDbObjectReactor* newObj) const;
    void                      removeReactor(UcDbObjectReactor* newObj) const;
    virtual void              addPersistentReactor(UcDbObjectId objId);
    virtual Ucad::ErrorStatus removePersistentReactor(UcDbObjectId objId);
    bool                      hasPersistentReactor(UcDbObjectId objId) const;
    UcDbVoidPtrArray*         reactors();
    const UcDbVoidPtrArray*   reactors() const;

    virtual void              recvPropagateModify(const UcDbObject* subObj);
    virtual void              xmitPropagateModify() const;

    virtual Ucad::ErrorStatus deepClone(UcDbObject* pOwnerObject,
                                        UcDbObject*& pClonedObject,
                                        UcDbIdMapping& idMap,
                                        ZSoft::Boolean isPrimary = true) const;
 
    virtual Ucad::ErrorStatus wblockClone(UcRxObject* pOwnerObject,
                                          UcDbObject*& pClonedObject,
                                          UcDbIdMapping& idMap,
                                          ZSoft::Boolean isPrimary = true) const;

    void              setUcDbObjectIdsInFlux();
    ZSoft::Boolean    isUcDbObjectIdsInFlux() const;

    virtual void cancelled       (const UcDbObject* dbObj);
    virtual void copied          (const UcDbObject* dbObj,
                                  const UcDbObject* newObj);
    virtual void erased          (const UcDbObject* dbObj,
                                  ZSoft::Boolean pErasing = true);
    virtual void goodbye         (const UcDbObject* dbObj);
    virtual void openedForModify (const UcDbObject* dbObj);
    virtual void modified        (const UcDbObject* dbObj);
    virtual void subObjModified  (const UcDbObject* dbObj,
                                  const UcDbObject* subObj);
    virtual void modifyUndone    (const UcDbObject* dbObj);
    virtual void modifiedXData   (const UcDbObject* dbObj);
    virtual void unappended      (const UcDbObject* dbObj);
    virtual void reappended      (const UcDbObject* dbObj);
    virtual void objectClosed    (const UcDbObjectId objId);
    virtual void modifiedGraphics(const UcDbEntity* dbEnt);

    virtual UcRxObject*        clone() const;
    virtual Ucad::ErrorStatus  copyFrom(const UcRxObject* pSrc);

    bool       hasSaveVersionOverride();
    void       setHasSaveVersionOverride(bool bSetIt);

    virtual Ucad::ErrorStatus getObjectSaveVersion(const UcDbDwgFiler* pFiler, 
                                 UcDb::UcDbDwgVersion& ver,
                                 UcDb::MaintenanceReleaseVersion& maintVer);
    virtual Ucad::ErrorStatus getObjectSaveVersion(const UcDbDxfFiler* pFiler, 
                                 UcDb::UcDbDwgVersion& ver,
                                 UcDb::MaintenanceReleaseVersion& maintVer);
            Ucad::ErrorStatus getObjectBirthVersion(
                                 UcDb::UcDbDwgVersion& ver,
                                 UcDb::MaintenanceReleaseVersion& maintVer);

    virtual Ucad::ErrorStatus   decomposeForSave(
                                UcDb::UcDbDwgVersion ver,
                                UcDbObject*& replaceObj,
                                UcDbObjectId& replaceId,
                                ZSoft::Boolean& exchangeXData);

    virtual UcGiDrawable*       drawable();

    virtual ZSoft::UInt32       setAttributes(UcGiDrawableTraits* pTraits);
    virtual ZSoft::Boolean      worldDraw(UcGiWorldDraw* pWd);
    virtual void                viewportDraw(UcGiViewportDraw* pVd);
    virtual ZSoft::Boolean      isPersistent() const;
    virtual UcDbObjectId        id() const;
    virtual void                setGsNode(UcGsNode* pNode);
    virtual UcGsNode*           gsNode() const;

    virtual Ucad::ErrorStatus   getClassID(CLSID* pClsid) const;

    bool              hasFields(void) const;
    Ucad::ErrorStatus getField(const ZTCHAR* pszPropName,
                               UcDbObjectId& fieldId) const;
    Ucad::ErrorStatus getField(const ZTCHAR* pszPropName, UcDbField*& pField,
                               UcDb::OpenMode mode) const;

    virtual Ucad::ErrorStatus setField(const ZTCHAR* pszPropName, UcDbField* pField,
                               UcDbObjectId& fieldId);

    virtual Ucad::ErrorStatus removeField(UcDbObjectId fieldId);
    virtual Ucad::ErrorStatus removeField(const ZTCHAR* pszPropName, UcDbObjectId& returnId);
    virtual Ucad::ErrorStatus removeField(const ZTCHAR* pszPropName);
    UcDbObjectId      getFieldDictionary(void) const;
    Ucad::ErrorStatus getFieldDictionary(UcDbDictionary*& pFieldDict, 
                             UcDb::OpenMode mode) const;
protected:
    UcDbObject();
private:
    friend class UcDbSystemInternals;
    UcDbImpObject*            mpImpObject;

	UcDbObject (const UcDbObject & );
	UcDbObject & operator = (const UcDbObject & );
};

class ZSOFT_NO_VTABLE UcDbXObject: public UcRxObject
{
public:
    UCRX_DECLARE_MEMBERS(UcDbXObject);

    virtual Ucad::ErrorStatus audit(UcDbAuditInfo* pAuditInfo);

    Ucad::ErrorStatus dwgIn(UcDbDwgFiler* pFiler);
    virtual Ucad::ErrorStatus dwgInFields(UcDbDwgFiler* pFiler);
    Ucad::ErrorStatus dwgOut(UcDbDwgFiler* pFiler) const;
    virtual Ucad::ErrorStatus dwgOutFields(UcDbDwgFiler* pFiler) const;

    Ucad::ErrorStatus dxfIn(UcDbDxfFiler* pFiler);
    virtual Ucad::ErrorStatus dxfInFields(UcDbDxfFiler* pFiler);
    Ucad::ErrorStatus dxfOut(UcDbDxfFiler* pFiler) const;
    virtual Ucad::ErrorStatus dxfOutFields(UcDbDxfFiler* pFiler) const;

    protected:
    UcDbXObject();
};

class UcCmComplexColor: public  UcDbXObject
{
public:
    UCRX_DECLARE_MEMBERS(UcCmComplexColor); 

    virtual UcCmComplexColor* incReference();
    virtual void              decReference();

    virtual Ucad::ErrorStatus getDescription(ZTCHAR*& desc) const;
    virtual Ucad::ErrorStatus getExplanation(ZTCHAR*& expl) const;

    virtual UcCmEntityColor::ColorMethod  colorMethod() const;
    virtual Ucad::ErrorStatus setColorMethod(
        UcCmEntityColor::ColorMethod eColorMethod);

    virtual bool              isByColor() const;
    virtual bool              isByLayer() const;
    virtual bool              isByBlock() const;
    virtual bool              isByACI()   const;
    virtual bool              isByPen ()  const;
    virtual bool              isForeground()   const;

    virtual ZSoft::UInt32     color() const;
    virtual Ucad::ErrorStatus setColor(ZSoft::UInt32 color);

    virtual Ucad::ErrorStatus setRGB  (ZSoft::UInt8 red, 
                                       ZSoft::UInt8 green, 
                                       ZSoft::UInt8 blue);
    virtual Ucad::ErrorStatus setRed  (ZSoft::UInt8 red);
    virtual Ucad::ErrorStatus setGreen(ZSoft::UInt8 green);
    virtual Ucad::ErrorStatus setBlue (ZSoft::UInt8 blue);
    virtual ZSoft::UInt8      red  () const;
    virtual ZSoft::UInt8      green() const;
    virtual ZSoft::UInt8      blue () const;

    virtual ZSoft::UInt16     colorIndex() const;
    virtual Ucad::ErrorStatus setColorIndex(ZSoft::UInt16 colorIndex);
    virtual ZSoft::UInt16     penIndex() const;   
    virtual Ucad::ErrorStatus setPenIndex (ZSoft::UInt16 penIndex);

    virtual Ucad::ErrorStatus copyFrom(const UcRxObject*);

    virtual Ucad::ErrorStatus dwgInFields(UcDbDwgFiler* pFiler);
    virtual Ucad::ErrorStatus dwgOutFields(UcDbDwgFiler* pFiler) const;
    virtual Ucad::ErrorStatus dxfInFields(UcDbDxfFiler* pFiler);
    virtual Ucad::ErrorStatus dxfOutFields(UcDbDxfFiler* pFiler) const;
    virtual Ucad::ErrorStatus audit(UcDbAuditInfo* pAuditInfo);

private:
    ZSoft::UInt16 refCount;
    UcCmEntityColor mColor;
};

class UcCmColor : public UcCmColorBase
{
public:
    UcCmColor();
    UcCmColor(const UcCmColor&);
    UcCmColor(const UcCmColorBase&);
    UcCmColor& operator=(const UcCmColor& inputColor);
    UcCmColor& operator=(const UcCmColorBase& inputColor);
    virtual ~UcCmColor();

    bool operator ==(const UcCmColor& color) const;
    bool operator !=(const UcCmColor& color) const;
    bool operator ==(const UcCmColorBase& color) const;
    bool operator !=(const UcCmColorBase& color) const;
    
    Ucad::ErrorStatus getDescription(ZTCHAR*& desc) const;
    Ucad::ErrorStatus getExplanation(ZTCHAR*& expl) const;

    virtual UcCmEntityColor::ColorMethod  colorMethod() const;
    virtual Ucad::ErrorStatus setColorMethod(UcCmEntityColor::ColorMethod eColorMethod);

    virtual bool    isByColor() const;
    virtual bool    isByLayer() const;
    virtual bool    isByBlock() const;
    virtual bool    isByACI()   const;
    virtual bool    isByPen () const;
    virtual bool    isForeground()   const;

    bool            isNone() const;

    virtual ZSoft::UInt32     color() const;
    virtual Ucad::ErrorStatus setColor(ZSoft::UInt32 color);

    virtual Ucad::ErrorStatus setRGB  (ZSoft::UInt8 red, 
                               ZSoft::UInt8 green, 
                               ZSoft::UInt8 blue);
    virtual Ucad::ErrorStatus setRed  (ZSoft::UInt8 red);
    virtual Ucad::ErrorStatus setGreen(ZSoft::UInt8 green);
    virtual Ucad::ErrorStatus setBlue (ZSoft::UInt8 blue);
    virtual ZSoft::UInt8      red  () const;
    virtual ZSoft::UInt8      green() const;
    virtual ZSoft::UInt8      blue () const;

    virtual ZSoft::UInt16     colorIndex() const;
    virtual Ucad::ErrorStatus setColorIndex(ZSoft::UInt16 colorIndex);
    virtual ZSoft::UInt16     penIndex() const;   
    virtual Ucad::ErrorStatus setPenIndex (ZSoft::UInt16 penIndex);

    virtual Ucad::ErrorStatus setNames(const ZTCHAR *colorName,
                                       const ZTCHAR *bookName = NULL);
    virtual const ZTCHAR *      colorName(void) const;
    virtual const ZTCHAR *      bookName(void) const;
    virtual const ZTCHAR *      colorNameForDisplay(void);
    virtual bool              hasColorName(void) const;
    virtual bool              hasBookName(void) const;

    UcCmEntityColor           entityColor(void) const;
    int                       dictionaryKeyLength(void) const;
	void					  getDictionaryKey(ZTCHAR *pKey, size_t nLen) const;
	void					  getDictionaryKey(ZTCHAR *pKey) const;//Deprecated: will be removed in future.
    Ucad::ErrorStatus         setNamesFromDictionaryKey(const ZTCHAR *);

    Ucad::ErrorStatus dwgIn(UcDbDwgFiler* pInputFiler);
    Ucad::ErrorStatus dwgOut(UcDbDwgFiler *pOutputFiler) const;

    Ucad::ErrorStatus dxfIn(UcDbDxfFiler* pFiler, int groupCodeOffset = 0);
    Ucad::ErrorStatus dxfOut(UcDbDxfFiler* pFiler, int groupCodeOffset = 0) const;

    Ucad::ErrorStatus audit(UcDbAuditInfo* pAuditInfo);

    Ucad::ErrorStatus serializeOut(void *pBuff, int *pBuflen,
                    UcDb::UcDbDwgVersion ver = UcDb::kDHL_CURRENT) const;

    Ucad::ErrorStatus serializeIn(const void *pBuff, int *pBuflen);

    static const ZSoft::UInt16 MaxColorIndex; 

    UcCmComplexColor* complexColor() const;
    void setComplexColor(UcCmComplexColor* pComplex);

    Ucad::ErrorStatus dwgInAsTrueColor(UcDbDwgFiler* pInputFiler); 
    Ucad::ErrorStatus dwgOutAsTrueColor(UcDbDwgFiler *pOutputFiler) const; 

private:

    enum NameFlags {    kNoNames            = 0x00,
                        kHasColorName       = 0x01,
                        kHasBookName        = 0x02
                    };

    static const ZSoft::UInt16 ComplexColorFlag; 
    bool isComplex() const;

    UcCmEntityColor::RGBM   mRGBM;
    ZTCHAR *                  mColorName;
    ZTCHAR *                  mBookName;
    ZSoft::UInt8            mNameFlags;

};

Ucad::ErrorStatus uccmGetColorFromACIName(UcCmColor& clr, const ZTCHAR *pInput);
Ucad::ErrorStatus uccmGetColorFromRGBName(UcCmColor& clr, const ZTCHAR *pInput);
Ucad::ErrorStatus uccmGetColorFromColorBookName(UcCmColor& clr, const ZTCHAR *pBookName, const ZTCHAR *pColorName);

void uccmGetLocalizedColorNames( const ZTCHAR* colors[9] );

class UcDbColor: public UcDbObject
{
public:
    UCDB_DECLARE_MEMBERS(UcDbColor);

    UcDbColor();
    virtual ~UcDbColor();

    void getColor(UcCmColor& color) const;
    void setColor(const UcCmColor& color);
    const UcCmEntityColor& entityColor(void) const;

    virtual Ucad::ErrorStatus   decomposeForSave(
                                UcDb::UcDbDwgVersion ver,
                                UcDbObject*& replaceObj,
                                UcDbObjectId& replaceId,
                                ZSoft::Boolean& exchangeXData);

    virtual Ucad::ErrorStatus   dwgInFields(UcDbDwgFiler* pFiler);
    virtual Ucad::ErrorStatus   dwgOutFields(UcDbDwgFiler* pFiler) const;

    virtual Ucad::ErrorStatus   dxfInFields(UcDbDxfFiler* pFiler);
    virtual Ucad::ErrorStatus   dxfOutFields(UcDbDxfFiler* pFiler) const;

    virtual Ucad::ErrorStatus wblockClone(UcRxObject* pOwnerObject,
                                          UcDbObject*& pClonedObject,
                                          UcDbIdMapping& idMap,
                                          ZSoft::Boolean isPrimary
                                          = true) const;
    
private:

    UcCmColor           m_color;    
    UcCmEntityColor     m_ecol;     

};

class ZSOFT_NO_VTABLE UcDbEntity: public UcDbObject
{
public:
    UCDB_DECLARE_MEMBERS(UcDbEntity);

    virtual ~UcDbEntity();

    UcDbObjectId                blockId() const;

    UcCmColor                   color() const;
    virtual Ucad::ErrorStatus   setColor(const UcCmColor& color,
                                  ZSoft::Boolean doSubents = true);
    ZSoft::UInt16               colorIndex() const;
    virtual Ucad::ErrorStatus   setColorIndex(ZSoft::UInt16 color,
                                  ZSoft::Boolean doSubents = true);
    UcCmEntityColor             entityColor() const;

    UcCmTransparency            transparency() const;
    virtual Ucad::ErrorStatus   setTransparency(const UcCmTransparency& trans,
                                  ZSoft::Boolean doSubents = true);

    ZTCHAR*                       plotStyleName() const;
    UcDb::PlotStyleNameType     getPlotStyleNameId(UcDbObjectId& id) const;
    virtual Ucad::ErrorStatus   setPlotStyleName(const ZTCHAR* newName,
                                  ZSoft::Boolean doSubents = true);
    virtual Ucad::ErrorStatus   setPlotStyleName(UcDb::PlotStyleNameType,
                                UcDbObjectId newId = UcDbObjectId::kNull,
                                ZSoft::Boolean doSubents = true);
    
    ZTCHAR*                       layer() const;
    UcDbObjectId                layerId() const;
    virtual Ucad::ErrorStatus   setLayer(const ZTCHAR* newVal,
                                  ZSoft::Boolean doSubents = true,
                                  bool allowHiddenLayer = false);
    virtual Ucad::ErrorStatus   setLayer(UcDbObjectId newVal,
                                  ZSoft::Boolean doSubents = true,
                                  bool allowHiddenLayer = false);

    ZTCHAR*                       linetype() const;
    UcDbObjectId                linetypeId() const;
    virtual Ucad::ErrorStatus   setLinetype(const ZTCHAR* newVal,
                                  ZSoft::Boolean doSubents = true);
    virtual Ucad::ErrorStatus   setLinetype(UcDbObjectId newVal,
                                  ZSoft::Boolean doSubents = true);

    ZTCHAR*                        material() const;
    UcDbObjectId                materialId() const;
    virtual Ucad::ErrorStatus   setMaterial(const ZTCHAR* newVal, ZSoft::Boolean doSubents = true);
    virtual Ucad::ErrorStatus   setMaterial(UcDbObjectId newVal, ZSoft::Boolean doSubents = true);

	enum VisualStyleType 
	{
		kFullVisualStyle,
		kFaceVisualStyle,
		kEdgeVisualStyle
	};
	virtual Ucad::ErrorStatus   setVisualStyle  (UcDbObjectId visualStyleId, VisualStyleType vsType = kFullVisualStyle,  ZSoft::Boolean doSubents = true);
	UcDbObjectId                visualStyleId   (VisualStyleType vsType = kFullVisualStyle) const;

    virtual Ucad::ErrorStatus getMaterialMapper(UcGiMapper& mapper) const;
    virtual Ucad::ErrorStatus setMaterialMapper(const UcGiMapper& mapper, ZSoft::Boolean doSubents = true);

    double                      linetypeScale() const;
    virtual Ucad::ErrorStatus   setLinetypeScale(double newval,
                                  ZSoft::Boolean doSubents = true);

    UcDb::Visibility            visibility() const;
    virtual Ucad::ErrorStatus   setVisibility(UcDb::Visibility newVal,
                                  ZSoft::Boolean doSubents = true);

    UcDb::LineWeight            lineWeight() const;
    virtual Ucad::ErrorStatus   setLineWeight(UcDb::LineWeight newVal,
                                  ZSoft::Boolean doSubents = true);

    virtual UcDb::CollisionType collisionType() const;

    virtual bool                castShadows() const;
    virtual void                setCastShadows(bool newVal);
    virtual bool                receiveShadows() const;
    virtual void                setReceiveShadows(bool newVal);

    Ucad::ErrorStatus           setPropertiesFrom(const UcDbEntity* pEntity,
                                  ZSoft::Boolean doSubents = true);

    virtual ZSoft::Boolean      isPlanar() const { return false; }
    virtual Ucad::ErrorStatus   getPlane(UcGePlane&, UcDb::Planarity&) const
                                    { return Ucad::eNotApplicable; }

    virtual void                getEcs(UcGeMatrix3d& retVal) const;

    virtual Ucad::ErrorStatus   getGeomExtents(UcDbExtents& extents) const;
    virtual  Ucad::ErrorStatus addSubentPaths(
                                  const UcDbFullSubentPathArray& newPaths);

    virtual  Ucad::ErrorStatus deleteSubentPaths(
                                  const UcDbFullSubentPathArray& paths);

    virtual  Ucad::ErrorStatus getSubentClassId(
                                  const UcDbFullSubentPath& path,
                                  CLSID*                    clsId) const;

    virtual  Ucad::ErrorStatus transformSubentPathsBy(
                                  const UcDbFullSubentPathArray& paths,
                                  const UcGeMatrix3d&            xform);

    virtual  Ucad::ErrorStatus getGripPointsAtSubentPath(
                                  const UcDbFullSubentPath&      path,
                                  UcDbGripDataPtrArray&          grips,
                                  const double                   curViewUnitSize,
                                  const int                      gripSize,
                                  const UcGeVector3d&            curViewDir,
                                  const int                      bitflags) const;

    virtual  Ucad::ErrorStatus moveGripPointsAtSubentPaths(
                                  const UcDbFullSubentPathArray& paths,
                                  const UcDbVoidPtrArray&        gripAppData,
                                  const UcGeVector3d&            offset,
                                  const int                      bitflags);

    virtual  Ucad::ErrorStatus getSubentPathGeomExtents(
                                  const UcDbFullSubentPath&      path,
                                  UcDbExtents&                   extents) const;

    virtual  Ucad::ErrorStatus getSubentPathsAtGsMarker(
                                  UcDb::SubentType       type,
                                  ZSoft::GsMarker        gsMark,
                                  const UcGePoint3d&     pickPoint,
                                  const UcGeMatrix3d&    viewXform, 
                                  int&                   numPaths,
                                  UcDbFullSubentPath*&   subentPaths, 
                                  int                    numInserts = 0,
                                  UcDbObjectId*          entAndInsertStack
                                                           = nullptr) const;

    virtual  Ucad::ErrorStatus getSubentPathsAtGsMarker(
                                  UcDb::SubentType       type,
                                  ZSoft::GsMarker        gsMark,
                                  const UcGePoint3d&     pickPoint,
                                  const UcGeFastTransform&  viewXform, 
                                  int&                   numPaths,
                                  UcDbFullSubentPath*&   subentPaths, 
                                  int                    numInserts = 0,
                                  UcDbObjectId*          entAndInsertStack
                                                           = NULL) const;

    virtual  Ucad::ErrorStatus getGsMarkersAtSubentPath(
                               const UcDbFullSubentPath& subPath, 
                               UcArray<ZSoft::GsMarker>& gsMarkers) const;

    virtual Ucad::ErrorStatus highlight(const UcDbFullSubentPath& subId 
                                        = kNullSubent, const ZSoft::Boolean highlightAll 
                        = false) const;
    virtual Ucad::ErrorStatus unhighlight(const UcDbFullSubentPath& subId 
                                        = kNullSubent, const ZSoft::Boolean highlightAll  
                        = false) const;
    virtual UcDbEntity*       subentPtr(const UcDbFullSubentPath& id) const;
 
    virtual Ucad::ErrorStatus   getOsnapPoints(
                                 UcDb::OsnapMode     osnapMode,
                                 ZSoft::GsMarker     gsSelectionMark,
                                 const UcGePoint3d&  pickPoint,
                                 const UcGePoint3d&  lastPoint,
                                 const UcGeMatrix3d& viewXform,
                                 UcGePoint3dArray&   snapPoints,
                                 UcDbIntArray&       geomIds) const;

    virtual Ucad::ErrorStatus   getOsnapPoints(
                                 UcDb::OsnapMode     osnapMode,
                                 ZSoft::GsMarker     gsSelectionMark,
                                 const UcGePoint3d&  pickPoint,
                                 const UcGePoint3d&  lastPoint,
                                 const UcGeFastTransform& viewXform,
                                 UcGePoint3dArray&   snapPoints,
                                 UcDbIntArray&       geomIds) const;

    virtual Ucad::ErrorStatus   getOsnapPoints(
                                 UcDb::OsnapMode     osnapMode,
                                 ZSoft::GsMarker     gsSelectionMark,
                                 const UcGePoint3d&  pickPoint,
                                 const UcGePoint3d&  lastPoint,
                                 const UcGeMatrix3d& viewXform,
                                 UcGePoint3dArray&   snapPoints,
                                 UcDbIntArray&       geomIds,
                                 const UcGeMatrix3d& insertionMat) const;

    virtual Ucad::ErrorStatus   getOsnapPoints(
                                 UcDb::OsnapMode     osnapMode,
                                 ZSoft::GsMarker     gsSelectionMark,
                                 const UcGePoint3d&  pickPoint,
                                 const UcGePoint3d&  lastPoint,
                                 const UcGeFastTransform& viewXform,
                                 UcGePoint3dArray&   snapPoints,
                                 UcDbIntArray&       geomIds,
                                 const UcGeMatrix3d& insertionMat) const;

    virtual Ucad::ErrorStatus   getGripPoints(
                                   UcGePoint3dArray&  gripPoints,
                                   UcDbIntArray&  osnapModes,
                                   UcDbIntArray&  geomIds) const;

    virtual  Ucad::ErrorStatus moveGripPointsAt(const UcDbIntArray& indices,
        const UcGeVector3d& offset);

    virtual Ucad::ErrorStatus   getGripPoints(UcDbGripDataPtrArray& grips,
        const double curViewUnitSize, const int gripSize, 
        const UcGeVector3d& curViewDir, const int bitflags) const;

    virtual  Ucad::ErrorStatus moveGripPointsAt(const UcDbVoidPtrArray& gripAppData,
        const UcGeVector3d& offset, const int bitflags);
    
    virtual Ucad::ErrorStatus getStretchPoints(
        UcGePoint3dArray& stretchPoints) const;
    virtual Ucad::ErrorStatus moveStretchPointsAt(const UcDbIntArray& indices,
        const UcGeVector3d& offset);

    virtual  Ucad::ErrorStatus intersectWith(const UcDbEntity* pEnt,
                                    UcDb::Intersect intType, 
                                    UcGePoint3dArray& points,
                                    ZSoft::GsMarker thisGsMarker = 0,
                                    ZSoft::GsMarker otherGsMarker = 0) const;
 
    virtual  Ucad::ErrorStatus intersectWith(const UcDbEntity* pEnt,
                                             UcDb::Intersect intType, 
                                             const UcGePlane& projPlane,
                                             UcGePoint3dArray& points, 
                                             ZSoft::GsMarker thisGsMarker = 0,
                                             ZSoft::GsMarker otherGsMarker = 0) const;

    Ucad::ErrorStatus          boundingBoxIntersectWith(
                                             const UcDbEntity*   pEnt,
                                             UcDb::Intersect     intType,
                                             UcGePoint3dArray&   points,
                                             ZSoft::GsMarker     thisGsMarker,
                                             ZSoft::GsMarker     otherGsMarker) const;

    Ucad::ErrorStatus          boundingBoxIntersectWith(
                                             const UcDbEntity*   pEnt,
                                             UcDb::Intersect     intType,
                                             const UcGePlane&    projPlane,
                                             UcGePoint3dArray&   points,
                                             ZSoft::GsMarker     thisGsMarker,
                                             ZSoft::GsMarker     otherGsMarker) const;

    virtual void                list() const;

    virtual Ucad::ErrorStatus   transformBy(const UcGeMatrix3d& xform);
    virtual Ucad::ErrorStatus   transformBy(const UcGeFastTransform& xform);
    virtual Ucad::ErrorStatus   getTransformedCopy(const UcGeMatrix3d& xform,
                                                   UcDbEntity*& pEnt) const;
    virtual Ucad::ErrorStatus   explode(UcDbVoidPtrArray& entitySet) const;

    void                        recordGraphicsModified(
                                    ZSoft::Boolean setModified = true);

    Ucad::ErrorStatus           draw();
    virtual ZSoft::Boolean      worldDraw(UcGiWorldDraw*        mode);
    virtual void                viewportDraw(UcGiViewportDraw*  mode);
    virtual void                saveAs(UcGiWorldDraw* mode, UcDb::SaveType st);

    virtual Ucad::ErrorStatus   getCompoundObjectTransform(UcGeMatrix3d & xMat) const;

    void                        setDatabaseDefaults();
    void                        setDatabaseDefaults(UcDbDatabase* pDb);
    virtual void                subSetDatabaseDefaults(UcDbDatabase* pDb);

    virtual Ucad::ErrorStatus   applyPartialUndo(UcDbDwgFiler* undoFiler,
                                                 UcRxClass*    classObj);

    virtual Ucad::ErrorStatus   audit(UcDbAuditInfo* pAuditInfo);

    virtual Ucad::ErrorStatus   dwgInFields(UcDbDwgFiler* pFiler);
    virtual Ucad::ErrorStatus   dwgOutFields(UcDbDwgFiler* pFiler) const;

    virtual Ucad::ErrorStatus   dxfInFields(UcDbDxfFiler* pFiler);
    virtual Ucad::ErrorStatus   dxfOutFields(UcDbDxfFiler* pFiler) const;

    virtual UcGiDrawable*       drawable();

    virtual ZSoft::UInt32       setAttributes(UcGiDrawableTraits* pTraits);
    virtual void                setGsNode(UcGsNode* pNode);
    virtual UcGsNode*           gsNode() const;
	virtual bool                bounds(UcDbExtents& bounds) const;

    virtual ZSoft::Boolean      cloneMeForDragging();
    virtual bool                hideMeForDragging() const;

    virtual void                dragStatus(const UcDb::DragStat status);
    virtual void                gripStatus(const UcDb::GripStat status);
    virtual void                subentGripStatus(
                                    const UcDb::GripStat      status,
                                    const UcDbFullSubentPath& subentity);
    virtual Ucad::ErrorStatus   getClassID(CLSID* pClsid) const;

    virtual Ucad::ErrorStatus getGripEntityUCS(const void* pGripAppData,
        UcGeVector3d& normalVec, UcGePoint3d& origin, UcGeVector3d& xAxis) const;

protected:
    
    UcDbEntity();

private:
	UcDbEntity (const UcDbEntity& );
	UcDbEntity & operator = (const UcDbEntity& );
};

inline UcDbEntity::~UcDbEntity()
{
    
}

class ZSOFT_NO_VTABLE UcDbObjectReactor: public UcRxObject
{
public:
    UCRX_DECLARE_MEMBERS(UcDbObjectReactor);

    virtual void cancelled      (const UcDbObject* dbObj);
    virtual void copied         (const UcDbObject* dbObj,
                                 const UcDbObject* newObj);
    virtual void erased         (const UcDbObject* dbObj,
                                 ZSoft::Boolean pErasing = true);
    virtual void goodbye        (const UcDbObject* dbObj);
    virtual void openedForModify(const UcDbObject* dbObj);
    virtual void modified       (const UcDbObject* dbObj);
    virtual void subObjModified (const UcDbObject* dbObj,
                                 const UcDbObject* subObj);
    virtual void modifyUndone   (const UcDbObject* dbObj);
    virtual void modifiedXData  (const UcDbObject* dbObj);
    virtual void unappended     (const UcDbObject* dbObj);
    virtual void reappended     (const UcDbObject* dbObj);
    virtual void objectClosed   (const UcDbObjectId objId);

protected:
    UcDbObjectReactor();
};

class ZSOFT_NO_VTABLE UcDbEntityReactor: public UcDbObjectReactor
{
public:
    UCRX_DECLARE_MEMBERS(UcDbEntityReactor);
    virtual void modifiedGraphics(const UcDbEntity* dbObj);
    virtual void dragCloneToBeDeleted (const UcDbEntity* pOriginalObj,
                                       const UcDbEntity* pClone);
protected:
    UcDbEntityReactor();
};

class ZSOFT_NO_VTABLE UcDbDatabaseReactor: public UcRxObject
{
public:
    UCRX_DECLARE_MEMBERS(UcDbDatabaseReactor);

    virtual void objectAppended       (const UcDbDatabase* dwg, const UcDbObject* dbObj);
    virtual void objectUnAppended     (const UcDbDatabase* dwg, const UcDbObject* dbObj);
    virtual void objectReAppended     (const UcDbDatabase* dwg, const UcDbObject* dbObj);
    virtual void objectOpenedForModify(const UcDbDatabase* dwg, const UcDbObject* dbObj);
    virtual void objectModified       (const UcDbDatabase* dwg, const UcDbObject* dbObj);
    virtual void objectErased         (const UcDbDatabase* dwg, const UcDbObject* dbObj,
                                        ZSoft::Boolean bErased);
    virtual void headerSysVarWillChange(const UcDbDatabase* dwg, const ZTCHAR* name);
    virtual void headerSysVarChanged   (const UcDbDatabase* dwg, const ZTCHAR* name,
                                        ZSoft::Boolean bSuccess);
    virtual void proxyResurrectionCompleted(const UcDbDatabase* dwg,
                                            const ZTCHAR* appname,
                                            UcDbObjectIdArray& objects);
    virtual void goodbye              (const UcDbDatabase* dwg);
};

class UcDbExtents2d : public UcHeapOperators
{
public:
	UcDbExtents2d();                                      
	UcDbExtents2d(const UcDbExtents2d& src);           
	UcDbExtents2d(const UcGePoint2d& min, const UcGePoint2d& max);  

	UcGePoint2d       minPoint() const { return mMinPoint; }
	UcGePoint2d       maxPoint() const { return mMaxPoint; }
	Ucad::ErrorStatus set(const UcGePoint2d& min, const UcGePoint2d& max);

	bool              operator==(const UcDbExtents2d& other);

private:
	UcGePoint2d    mMinPoint;
	UcGePoint2d    mMaxPoint;
};

class UcDbExtents : public UcHeapOperators
{
public:
    UcDbExtents();                                      
    UcDbExtents(const UcDbExtents& src);           
    UcDbExtents(const UcGePoint3d& min, const UcGePoint3d& max);  
 
    UcGePoint3d       minPoint() const { return mMinPoint; }
    UcGePoint3d       maxPoint() const { return mMaxPoint; }
    Ucad::ErrorStatus set(const UcGePoint3d& min, const UcGePoint3d& max);

    void              addPoint (const UcGePoint3d& pt);
    void              addExt   (const UcDbExtents& src);
    Ucad::ErrorStatus addBlockExt(UcDbBlockTableRecord* pBTR);

    void expandBy(const UcGeVector3d& vec);
    void transformBy(const UcGeMatrix3d& mat);

	bool              operator==(const UcDbExtents& other);
private:
    UcGePoint3d    mMinPoint;
    UcGePoint3d    mMaxPoint;
};

inline Ucad::ErrorStatus
UcDbDatabase::getBlockTable(
    UcDbBlockTable*& pTable,
    UcDb::OpenMode mode)
{
    return getSymbolTable(pTable, mode);
}

inline Ucad::ErrorStatus
UcDbDatabase::getLayerTable(
    UcDbLayerTable*& pTable,
    UcDb::OpenMode mode)
{
    return getSymbolTable(pTable, mode);
}

inline Ucad::ErrorStatus
UcDbDatabase::getTextStyleTable(
    UcDbTextStyleTable*& pTable,
    UcDb::OpenMode mode)
{
    return getSymbolTable(pTable, mode);
}

inline Ucad::ErrorStatus
UcDbDatabase::getLinetypeTable(
    UcDbLinetypeTable*& pTable,
    UcDb::OpenMode mode)
{
    return getSymbolTable(pTable, mode);
}

inline Ucad::ErrorStatus
UcDbDatabase::getViewTable(
    UcDbViewTable*& pTable,
    UcDb::OpenMode mode)
{
    return getSymbolTable(pTable, mode);
}

inline Ucad::ErrorStatus
UcDbDatabase::getUCSTable(
    UcDbUCSTable*& pTable,
    UcDb::OpenMode mode)
{
    return getSymbolTable(pTable, mode);
}

inline Ucad::ErrorStatus
UcDbDatabase::getViewportTable(
    UcDbViewportTable*& pTable,
    UcDb::OpenMode mode)
{
    return getSymbolTable(pTable, mode);
}

inline Ucad::ErrorStatus
UcDbDatabase::getRegAppTable(
    UcDbRegAppTable*& pTable,
    UcDb::OpenMode mode)
{
    return getSymbolTable(pTable, mode);
}

inline Ucad::ErrorStatus
UcDbDatabase::getDimStyleTable(
    UcDbDimStyleTable*& pTable,
    UcDb::OpenMode mode)
{
    return getSymbolTable(pTable, mode);
}

#define UC_SRCH_BLOCK         0x01
#define UC_SRCH_DIM_TEXT      0x02
#define UC_SRCH_TEXT          0x04
#define UC_SRCH_LINK_DESC     0x08
#define UC_SRCH_LINK_URL      0x10
#define UC_SRCH_MATCH_CASE    0x20
#define UC_SRCH_WHOLE_WORD    0x40

#define UC_SRCH_DEFAULT       0x1F

bool ucdbTextFind(UcDbDatabase* pDatabase,
                  UcDbObjectIdArray& resultSet,
                  const ZTCHAR* findString,
                  const ZTCHAR* replaceString = nullptr,
                  ZSoft::UInt8 searchOptions = UC_SRCH_DEFAULT,
                  const UcDbObjectIdArray& selSet = 0);

#pragma pack(pop)

#endif
